package com.mes.cloud.web;

import com.mes.cloud.api.dto.request.SysParamPageRequest;
import com.mes.cloud.api.dto.request.SysParamRequest;
import com.mes.cloud.api.dto.response.SysParamDto;
import com.mes.cloud.common.CommPager;
import com.mes.cloud.common.JsonResult;
import com.mes.cloud.service.SysParamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author Mr.zhang
 * @email zhangchao4@shinho.net.cn
 * @version 2019-08-02 10:37:18
 */
@Api(tags = "系统参数表", value = "系统参数表接口")
@RestController
@RequestMapping(value = "/sysParam")
public class SysParamController  {

    private SysParamService sysParamService;

    @Autowired
    public SysParamController(SysParamService sysParamService) {
        this.sysParamService = sysParamService;
    }

    /**
     * 功能: 系统参数表分页查询
     *
     * @param pageRequest
     * @return JsonResult<CommPager<SysParamDto>>
     */
    @ApiOperation(value = "系统参数表分页查询", notes = "系统参数表分页查询")
    @PostMapping(value = "/listPage")
    public JsonResult<CommPager<SysParamDto>> pageList(@Valid @RequestBody SysParamPageRequest pageRequest) {
        return sysParamService.pageList(pageRequest);
    }

    /**
     * 功能: 系统参数表新增
     *
     * @param sysParamRequest
     * @return JsonResult
     */
    @ApiOperation(value = "系统参数表新增", notes = "系统参数表新增")
    @PostMapping(value = "/add")
    public JsonResult add(@Valid @RequestBody SysParamRequest sysParamRequest) {
        return sysParamService.insert(sysParamRequest);
    }

    /**
     * 功能: 系统参数表修改
     *
     * @param sysParamRequest
     * @return JsonResult
     */
    @ApiOperation(value = "系统参数表修改", notes = "系统参数表修改")
    @PostMapping(value = "/update")
    public JsonResult update(@Valid @RequestBody SysParamRequest sysParamRequest) {
        return sysParamService.update(sysParamRequest);

    }

    /**
     * 功能: 系统参数表查看详情
     *
     * @param id
     * @return JsonResult
     */
    @ApiOperation(value = "系统参数表查看详情", notes = "系统参数表查看详情")
    @ApiImplicitParam(paramType = "String", name = "id", value = "系统参数表主键", required = true)
    @GetMapping(value = "get/{id}")
    public JsonResult<SysParamDto> get(@PathVariable String id) {
        return sysParamService.get(id);
    }

    @ApiOperation(value = "查询系统参数表", notes = "查询系统参数表")
    @ApiImplicitParam(paramType = "String", name = "code", value = "系统参数表code", required = true)
    @GetMapping(value = "getSysParam/{code}")
    public JsonResult<SysParamDto> getSysParam(@PathVariable String code) {
        return sysParamService.getSysParam(code);
    }

}
